package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 新增床位
     *
     * @param bedDto 前端传递的床位数据
     */
    @Override
    public void addBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto, bed);
        bedMapper.addBed(bed);
    }

    @Override
    public BedVo getBedById(Long id) {
        Bed bed = bedMapper.getBedById(id);
        BedVo vo = new BedVo();
        BeanUtils.copyProperties(bed, vo);

        return vo;
    }

    /**
     * 根据id修改床位的数据
     *
     * @param bedDto
     * @return
     */
    @Override
    public int updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto, bed);

        //设置更新时间和更新人
        bed.setUpdateTime(LocalDateTime.now());
        bed.setUpdateBy(1L); //后期再修改 先写死

        return bedMapper.updateBed(bed);
    }

    /**
     * 根据id删除床位
     *
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        bedMapper.deleteById(id);
    }

}

